/**
 * @param {string} s
 * @return {number}
 */
 var numberOfWays = function(s) {
  const n = s.length
  const zero = new Array(n).fill(0)
  zero[0] = Number(s[0]) ^ 1
  const one = new Array(n).fill(0)
  one[0] = Number(s[0]) & 1
  for(let i = 1; i<n; i++) {
    zero[i] = zero[i-1] + (Number(s[i]) ^ 1)
    one[i] = one[i-1] + (Number(s[i]) & 1)
  }
  let ans = 0
  for(let i = 1; i<n; i++) {
    if(s[i] === '0') {
      ans += one[i-1] * (one[n-1] - one[i])
    } else {
      ans += zero[i-1] * (zero[n-1] - zero[i])
    }
  }
  return ans
};